<?php
session_start();
include_once("conn.php");

date_default_timezone_set('PRC');   //设置时区为中国时间；

$name = $_POST["new_user"];
$password  = $_POST["new_password"];
$email = $_POST["new_email"];
$sex = $_POST["new_sex"];
$xuehao = $_POST["new_xuehao"];
$date = date("Y-m-d H:i:s");

$query = "select * from bbs_user where u_name = '".$name."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

$query2 = "select * from bbs_user where u_email = '".$email."'";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_array($result2);

if($row["u_name"]==$name)
{
	echo "<script>alert('该用户名已经被占用');history.back();</script>";
	exit;
}

else if($row2["u_email"]==$email)
{
	echo "<script>alert('该邮箱已经被注册过');history.back();</script>";
	exit;
}

else {

	$query = "insert into bbs_user(u_name,u_password,u_email,u_sex,u_xuehao,u_regtime,u_lastlogintime) values('".$name."','".$password."','".$email."','".$sex."','".$xuehao."','".$date."','".$date."')";

	$result = mysql_query($query);

	$_SESSION["current_user"] = $name;
	$_SESSION["login_count"] = 1;
	$_SESSION["lastlogintime"] = date("Y-m-d H:i:s",time());

	echo "<script>alert('注册成功');window.location.href='index.php';</script>";
	
	if(!$result) {
		echo "<script>alert('注册失败');history.back();</script>";
	}

}


?>